<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="fmt" uri="jakarta.tags.fmt" %>

<div class="admin-table">
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>昵称</th>
                <th>角色</th>
                <th>注册时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${users}" var="user">
                <tr>
                    <td>${user.id}</td>
                    <td>${user.username}</td>
                    <td>${user.nickname}</td>
                    <td>${user.role == 1 ? '管理员' : '普通用户'}</td>
                    <td>
                        <fmt:parseDate value="${user.createTime}" pattern="yyyy-MM-dd'T'HH:mm" var="parsedDateTime" type="both"/>
                        <fmt:formatDate value="${parsedDateTime}" pattern="yyyy-MM-dd HH:mm"/>
                    </td>
                    <td>
                        <button type="button" class="btn-small" onclick="showEditUserModal('${user.id}')">编辑</button>
                        <c:if test="${user.role != 1}">
                            <button type="button" class="btn-small btn-danger" onclick="deleteUser('${user.id}')">删除</button>
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
</div>

<!-- 编辑用户模态框 -->
<div id="editUserModal" class="modal">
    <div class="modal-content">
        <h3>编辑用户</h3>
        <form id="editUserForm" method="post" onsubmit="return false;">
            <input type="hidden" name="id">
            <div class="form-group">
                <label>用户名</label>
                <input type="text" name="username" readonly>
            </div>
            <div class="form-group">
                <label>昵称</label>
                <input type="text" name="nickname" required>
            </div>
            <div class="form-group">
                <label>角色</label>
                <select name="role">
                    <option value="0">普通用户</option>
                    <option value="1">管理员</option>
                </select>
            </div>
            <div class="form-actions">
                <button type="submit" class="btn-primary">保存</button>
                <button type="button" onclick="closeModal('editUserModal')" class="btn">取消</button>
            </div>
        </form>
    </div>
</div>

<script src="/static/js/admin-users.js"></script> 